home *** CD-ROM | disk | FTP | other *** search
/ Varios Español / Varios Español.iso / DBASE5 / SAMPLES.ZIP / FACTURAS.PRG < prev    next >
Text File  |  1994-10-12  |  11KB  |  364 lines

  1. ******************************************************************************
  2. * PROGRAM NAME: INVOICES.PRG
  3. *               SAMPLE CUSTOM REPORT - INVOICES
  4. *               GENERATES INVOICES & UPDATES ACCT_REC.DBF
  5. *               SAMPLE BUSINESS APPLICATION
  6. * LAST CHANGED: 09/25/89 09:26AM
  7. * WRITTEN BY:   Borland International Inc.
  8. ******************************************************************************
  9. *              Logic and some variable names modeled after reports generator
  10. ******************************************************************************
  11. *
  12. *DO WHILE .NOT. PRINTSTATUS()
  13.  *  DO ErrorMsg WITH "Impresora no preparada. Pulse Esc para cancelar"
  14.   * RETURN
  15. *ENDDO
  16.  
  17. CLEAR
  18. inv_month = 0
  19.  
  20.    ?? CHR(7)
  21.    inv_month = MONTH(DATE())-1
  22.    @ 10, 8 CLEAR TO 14,72
  23.    @ 12,5 SAY "¿Procesar facturas del mes (1-12, 0 para Abandonar)?" ;
  24.           GET inv_month PICTURE "99" RANGE 0,12
  25.    READ
  26.     IF Inv_Month=0 .or. lastkey()=27
  27.         CLEAR
  28.         RETURN
  29.     ENDIF
  30. set talk off
  31. * Open database files and choose active indexes
  32. SELECT 1
  33. USE Pedidos   ORDER Pedido
  34. USE Cli       ORDER Cod_cli IN 2
  35. USE Mov_ctas  ORDER Cod_cli IN 3
  36. USE Articulo  ORDER Cod_art IN 4
  37. * Relate database files and activate the relation
  38. SET RELATION TO Cod_cli INTO Cli, Cod_cli INTO Mov_ctas, Cod_art INTO Articulo
  39. GO TOP
  40.  
  41. * If user presses Esc during printing, exit
  42. ON ESCAPE DO Stop_rpt
  43.  
  44. * Process errors
  45. * ON ERROR DO Errormsg
  46.  
  47. * Set up environment
  48. SET SPACE OFF
  49. _plineno  =  0
  50. _peject   = "NONE"
  51. _pageno   = 1
  52.  
  53. * Initialize variables
  54. continu_on  = .T.               && Continue printing flag - set by Esc to .F.
  55. complete = .F.
  56. on_pg_line = 0                  && Line at which ON PAGE works
  57. STORE 0  TO amt_of_bil, amt_of_cur, inv_amount, oldbalance
  58. STORE 0  TO inv_count, ord_count, grand_tot, tot_price
  59. STORE "" TO invoice_no, mcust_id, today, this_year, this_month
  60. today      = DTOC(DATE())
  61. this_year  = RIGHT(today,2)
  62. this_month = LEFT(today,2)
  63.  
  64. * Calculate line no. to break page on
  65. on_pg_line = INT(_plength - 6)  && Height minus footer and margin
  66.  
  67. * Set up line number where page break procedure executes
  68. ON PAGE AT LINE on_pg_line DO Page_brk
  69.  
  70. SET CONSOLE off
  71. SET PRINTER on
  72. *================================ Begin Print Job ============================
  73. PRINTJOB
  74.    * ======= File loop - process records in index order to end of file =======
  75.    *                     or until user presses Esc (continu_on = .F.)
  76.    * Process all uninvoiced records for a particular customer
  77.    SCAN FOR .NOT. facturado .AND. inv_month = MONTH(Fech_trans) ;
  78.     WHILE continu_on
  79.       mcust_id = cust_id
  80.       DO Pg_head      && Print standard page heading
  81.       DO Inv_head     && Print invoice heading
  82.       complete = .F.  && Flag customer's invoices not completely processed
  83.       * Print orders for this customer
  84.       SCAN FOR .NOT. Facturado .AND. inv_month = MONTH(Fech_trans) ;
  85.        WHILE Cod_cli = mCod_cli .AND. continu_on
  86.      DO Detail
  87.       ENDSCAN
  88.       complete = .T.  && Flag customer's invoices are completely processed
  89.       SKIP -1         && Return to last record for customer
  90.       DO Inv_calc     && Print invoice total for last customer
  91.       EJECT PAGE      && Print invoice footer - Inv_foot called by ON PAGE
  92.       DO Updat_ar     && Update Acct_rec database file with processed data
  93.       DO Reinit       && Re-initialize summary variables
  94.    ENDSCAN
  95.    IF continu_on
  96.       * End of file - User did not press Esc to stop printing
  97.       message = "Finalizado el proceso e impresión de facturas del mes " ;
  98.         + STR(inv_month,2)
  99.    ELSE
  100.       * Not EOF - User pressed Esc to stop printing
  101.       message = "Facturas NO FINALIZADAS. Detenido por el usuario a las " + TIME()
  102.    ENDIF
  103.    DO Rpt_end WITH message
  104.    ON PAGE
  105. ENDPRINTJOB
  106. *============================= End Print Job =================================
  107. EJECT PAGE
  108. ON PAGE
  109. SET CONSOLE on
  110. SET PRINTER off
  111. CLEAR
  112.  
  113.    ?? CHR(7)
  114.    @ 10,12 SAY "COPIANDO pedidos procesados, espere por favor...          "
  115.    @ 12,10 SAY SPACE(61)
  116.    @ 13,10 SAY SPACE(63)
  117.  
  118.    CLOSE DATABASES
  119.    * Create an archive database file for processed orders.
  120.    * Records will be copied to it, then erased from Orders.
  121.    IF .NOT. FILE("Archiv_o.dbf")
  122.       USE Pedidos
  123.       COPY STRUCTURE TO Archiv_o
  124.    ENDIF
  125.    USE Archiv_o
  126.  
  127.    APPEND FROM Pedidos FOR Facturado
  128.  
  129.    *-- Remove the archived records from Orders
  130.    USE Pedidos EXCLUSIVE
  131.    SET TALK on
  132.    DELETE ALL FOR Facturado
  133.    @ 10,10 SAY "ELIMINANDO pedidos procesados, espere por favor...   "
  134.    PACK
  135.    SET TALK off
  136. ON ESCAPE
  137. ON ERROR
  138. CLOSE ALL
  139. SET PROCEDURE TO
  140. SET CONSOLE ON
  141. IF FILE("ARCHIV_O.DBF")
  142.     DELE FILE ARCHIV_O.DBF
  143. ENDIF
  144. CLEAR
  145. RETURN
  146. ********************* END OF MAIN REPORT PROCEDURE ***************************
  147.  
  148. * UTILITY PROCEDURES
  149.  
  150.  
  151. PROCEDURE Detail
  152.    * Imprimir apartado de detalle del informe
  153.    ?? Fech_trans       AT 0,
  154.    ?? Cod_art          AT 10,
  155.    ?? Articulo->Nom_art AT 21,
  156.    ?? Can_art         AT 53 PICTURE "999",
  157.    ?? Articulo->Precio     AT 58 PICTURE "9,999,999",
  158.    * Extend price
  159.    tot_price  = ROUND(Can_art * Articulo->Precio,2)
  160.    ?? tot_price        AT 70 PICTURE "9,999,999"
  161.    ?
  162.    * Accumulate total amount of current invoice
  163.    Imp_fac = Imp_fac + tot_price
  164.    * Accumulate number of orders processed
  165.    ord_count  = ord_count + 1
  166.    * Update the posted flag "invoiced" to .T. in Orders dbf for this order
  167.    REPLACE Facturado WITH .T.
  168. RETURN
  169.  
  170.  
  171. PROCEDURE Inv_calc
  172.    * Print calculated summary data on details at cust_id break
  173.    Imp_cta = Imp_fac + Balanc_ant
  174.    ?? "----------" AT 69
  175.    ?
  176.    ?? "IMPORTE DE FACTURA" AT 0,
  177.    ?? "Ptas" AT 64,
  178.    ?? Imp_fac PICTURE "99,999,999" AT 69
  179.    ?
  180.    IF Balanc_ant <> 0
  181.       ?? "----------" AT 69
  182.       ? "+ BALANCE ANTERIOR"
  183.       ?? Balanc_ant PICTURE "99,999,999" AT 69,
  184.       ?
  185.    ENDIF
  186.    ?? "==========" AT 69
  187.    ?
  188.    ?? "CANTIDAD TOTAL DEBIDA" STYLE "B" AT 0,
  189.    ?? "Ptas" STYLE "B" AT 64,
  190.    ?? Imp_cta PICTURE "99,999,999" STYLE "B" AT 69
  191.    ?
  192.    ?? "==========" AT 69
  193.    * Acumular cuentas totales para fin de informe
  194.    grand_tot = grand_tot + Imp_cta
  195.    ?
  196.    ?
  197. RETURN
  198.  
  199. PROCEDURE Inv_foot
  200.    * Imprimir pie de página de la factura
  201.    ?
  202.    ? "FORMA DE PAGO: " AT 27,Cli->F_pago
  203.    ?
  204.    ? Mov_ctas->Notas  AT 18
  205.    * Comenzar nueva pßgina
  206.    EJECT PAGE
  207. RETURN
  208.  
  209. PROCEDURE Inv_head
  210.    * Codigo nuevo número de factura
  211.    Num_fac = Cod_cli + this_year + this_month
  212.    * Incrementar contador de facturas
  213.    inv_count  = inv_count + 1
  214.    ?
  215.    ?? "FACTURA Nº: " STYLE "B" AT 0,
  216.    ?? Num_fac STYLE "B" FUNCTION "T" PICTURE "XXXXXXXXXX" ,
  217.    ?? DATE() AT 69
  218.    ?
  219.    ?
  220.    ?? "Cliente Nº: " AT 0,
  221.    ?? Cod_cli FUNCTION "T" PICTURE "XXXXXX"
  222.    ?
  223.    ?
  224.    ?? Cli->Cliente AT 0
  225.    ?
  226.    ?? Cli->Direccion1 AT 0, Cli->Direccion2 AT LEN(TRIM(Cli->Direccion1))+2
  227.    ?
  228.    ?? Cli->Ciudad PICTURE "@T XXXXXXXXXXXXXXXXXXXX" AT 0,
  229.    ?? ", ",
  230.    ?? Cli->Provincia," ",
  231.    ?? Cli->Cod_post
  232.    ?
  233.    ?? "ATENCION: " AT 0 ,
  234.    ?? Cli->Contacto PICTURE "@T XXXXXXXXXXXXXXXXXXXX","  ",
  235.    ?? Cli->Tel_cont
  236.    ?
  237.    ?  REPLICATE(CHR(205),80)        && Dibujar línea doble horizontal de 80    ?
  238.    ?
  239.    ?
  240.    ?? "ESTADO ANTERIOR:" STYLE "BU" AT 0
  241.    ?
  242.    ?? "FACTURA Nº:" AT 4, Mov_ctas->Num_ultfac AT 15
  243.    ?? "FECHA:" AT 31, Mov_ctas->Fch_ultfac AT 37
  244.    ?
  245.    ?? "IMPORTE Pt" AT 4, Mov_ctas->Imp_ultcta PICTURE "99,999,999" AT 15
  246.    ?
  247.    ?? "PAGADO  Pt" AT 4, Mov_ctas->Imp_ultpag PICTURE "99,999,999" AT 15
  248.    ?
  249.    ?? "----------" AT 15
  250.    ?
  251.    ?? "BALANCE t" AT 4
  252.    Balanc_ant = Mov_ctas->Balanc_ant
  253.    ?? Balanc_ant PICTURE "99,999,999" AT 15
  254.    ?
  255.    ?
  256.    ?? "ESTADO ACTUAL:" STYLE "BU" AT 0
  257.    ?  REPLICATE(CHR(196),80)        && Dibujar línea doble horizontal de 80    ?  "Pedido"    AT 0
  258.    ?  "Fecha"              AT 0
  259.    ?? "Nº artí."     AT 10
  260.    ?? "Descripcion" AT 21
  261.    ?? "Cant."              AT 53
  262.    ?? "Precio"             AT 61
  263.    ?? "Importe"            AT 70
  264.    ?  REPLICATE(CHR(196),80)        && Dibujar línea doble horizontal de 80    ?
  265. RETURN
  266.  
  267. PROCEDURE Page_brk
  268.    * Page break logic - occurs when report detail line = on_pg_line
  269.    DO Inv_foot
  270.    * Print heading if customer's invoices were not completed on prior page
  271.    IF .NOT. EOF() .AND. .NOT. complete
  272.       DO Pg_head
  273.    ENDIF
  274. RETURN
  275.  
  276. PROCEDURE Pg_head
  277.    * Print information at top of each invoice page
  278.    ?
  279.    ?  "Página " ,
  280.    ?? _pageno PICTURE "999"
  281.    ?
  282.    ?
  283.    ?  "A-T  INDUSTRIAS DEL MUEBLE" STYLE "B"   AT 27
  284.    ?
  285.    DEFINE BOX FROM 34 TO 45 HEIGHT 3 SINGLE
  286.    ?
  287.    ?? "FACTURA" STYLE "B" AT 36
  288.    ?
  289.    ?
  290.    ?  REPLICATE(CHR(205),80)        && Draw double line 80 characters wide
  291.    ?
  292. RETURN
  293.  
  294. PROCEDURE Reinit
  295.    * Re-initialize summary/calculation variables at customer breaks
  296.    STORE 0 TO Imp_fac, inv_amount
  297.    _pageno = 1
  298. RETURN
  299.  
  300. PROCEDURE Rpt_end
  301.    PARAMETERS message
  302.    * Print end-of-report summary data
  303.    ?
  304.    ?
  305.    ?  "A-T  INDUSTRIAS DEL MUEBLE"    AT 27
  306.    ?  "=========================="    AT 27
  307.    ?
  308.    ?  "PAGINA RESUMEN"  AT 33
  309.    ?
  310.    inv_date = CTOD(STR(inv_month,2)+RIGHT(DTOC(DATE()),6))
  311.    ?  "DEL MES DE " AT 29, UPPER(CMONTH(inv_date))
  312.    ?
  313.    ?
  314.    ?
  315.    ?  REPLICATE(CHR(205),80)        && Draw double line 80 characters wide
  316.    ?  DATE() AT 0 ,
  317.    ?? TIME() AT 69
  318.    ?  REPLICATE(CHR(205),80)        && Draw double line 80 characters wide
  319.    ?
  320.    ?
  321.    ?
  322.    ?
  323.    ?? "===========" AT 67,
  324.    ?
  325.    ?? "TOTAL " AT 0,
  326.    ?? inv_count PICTURE "999",
  327.    ?? " facturas " AT 21,
  328.    ?? "y ", ord_count PICTURE "9,999",
  329.    ?? " pedidos:",
  330.    ?? "Pts" AT 64,
  331.    ?? grand_tot PICTURE "99,999,999" ,
  332.    ?
  333.    ?? "===========" AT 67
  334.    ?
  335.    ?
  336.    ?
  337.    ?  message AT 6
  338.    ?
  339. RETURN
  340.  
  341. PROCEDURE Stop_rpt
  342.    continu_on = .F.   && Set stop printing flag to .F. when user presses Esc
  343. RETURN
  344.  
  345. PROCEDURE Updat_ar
  346.    * Actualizar registro del fichero relacionado Mov_ctas para este cliente con los datos
  347.    * procesados/calculados durante la facturación de los datos anteriores
  348.    SELECT Mov_ctas
  349.    IF Pedidos->Cod_cli <> Cod_cli
  350.       * Si el cliente nunca había sido facturado antes, crear un registro de cliente
  351.       APPEND BLANK
  352.       REPLACE Cod_cli WITH Pedidos->Cod_cli
  353.    ENDIF
  354.    REPLACE Num_ultfac WITH Num_fac, Fch_ultfac WITH Fecha_fac, ;
  355.        Imp_ultpag WITH Imp_pag, Imp_ultcta WITH Imp_fac, ;
  356.        Balanc_ant WITH Imp_ultcta - Imp_ultpag, Comentario WITH "", ;
  357.        Notas WITH "", Num_fac WITH m->Num_fac, ;
  358.        Fecha_fac WITH DATE(), Imp_fac WITH m->Imp_fac, ;
  359.        Imp_cta WITH m->Imp_cta
  360.    SELECT Pedidos
  361. RETURN
  362.  
  363. ****************************************** END OF FACTURAS.PRG ***************
  364.